<?php
namespace Site\Controller;
class EditorController extends CommonController {

    public function index(){
        $action = I('get.action');
        try {
            switch($action) {
                case 'config':
                    $config = file_get_contents(CONF_PATH . 'editor.json');
                    echo preg_replace('/\/\*[\s\S]+?\*\//', '', $config);
                    exit();
                    break;
                case 'upload':
                    $info = uploadImage('image','article');
                    break;
                default:
                    E('请求地址错误');
            }
        }catch(\Exception $e) {
            echo json_encode(array(
                'state'=> $e->getMessage()
            ));exit();
        }

        echo json_encode(array(
            'state'     => 'SUCCESS',
            'url'       => $info['path'],
        ));
    }
}
?>
